package com.business.appealtype.controller.gen;

import com.business.appealtype.model.auto.AppealType;
import com.business.appealtype.service.AppealTypeService;
import com.business.system.common.base.BaseController;
import com.business.system.common.domain.AjaxResult;
import com.business.system.model.custom.TableSplitResult;
import com.business.system.model.custom.Tablepar;
import com.business.system.model.custom.TitleVo;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("AppealTypeController")
@Api(value = "诉求类型")
public class AppealTypeController extends BaseController{

	private String prefix = "gen/appealType";
	@Autowired
	private AppealTypeService appealTypeService;

	@GetMapping("view")
	public String view(ModelMap model)
	{
		String str="诉求类型";
		setTitle(model, new TitleVo("列表", str+"管理", true,"欢迎进入"+str+"页面", true, false));
		return prefix + "/list";
	}

	//@Log(title = "诉求类型集合查询", action = "111")
	@PostMapping("list")
	@ResponseBody
	public Object list(Tablepar tablepar,String searchTxt){
		PageInfo<AppealType> page=appealTypeService.list(tablepar,searchTxt) ;
		TableSplitResult<AppealType> result=new TableSplitResult<AppealType>(page.getPageNum(), page.getTotal(), page.getList());
		return  result;
	}

	/**
	 * 新增
	 */

	@GetMapping("/add")
	public String add(ModelMap modelMap)
	{
		return prefix + "/add";
	}

	//@Log(title = "诉求类型新增", action = "111")
	@PostMapping("add")
	@ResponseBody
	public AjaxResult add(AppealType appealType){
		int b=appealTypeService.insertSelective(appealType);
		if(b>0){
			return success();
		}else{
			return error();
		}
	}

	/**
	 * 删除用户
	 * @param ids
	 * @return
	 */
	//@Log(title = "诉求类型删除", action = "111")
	@PostMapping("remove")
	@ResponseBody
	public AjaxResult remove(String ids){
		int b=appealTypeService.deleteByPrimaryKey(ids);
		if(b>0){
			return success();
		}else{
			return error();
		}
	}

	/**
	 * 检查用户
	 * @param tsysUser
	 * @return
	 */
	@PostMapping("checkNameUnique")
	@ResponseBody
	public int checkNameUnique(AppealType appealType){
		int b=appealTypeService.checkNameUnique(appealType);
		if(b>0){
			return 1;
		}else{
			return 0;
		}
	}


	/**
	 * 修改跳转
	 * @param id
	 * @param mmap
	 * @return
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") String id, ModelMap mmap)
	{
		mmap.put("AppealType", appealTypeService.selectByPrimaryKey(id));

		return prefix + "/edit";
	}

	/**
	 * 修改保存
	 */
	//@Log(title = "诉求类型修改", action = "111")
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(AppealType record)
	{
		return toAjax(appealTypeService.updateByPrimaryKeySelective(record));
	}

	/**
	 * 根据id查询唯一的诉求类型
	 * @param id
	 * @return
	 */
	@GetMapping("/selectOne/{id}")
	@ResponseBody
	public AjaxResult selectOne(@PathVariable("id")  String id){
		AppealType appealType = appealTypeService.selectByPrimaryKey(id);
		return AjaxResult.success().put("appealType",appealType);
	}




}
